package com.ruoyi.quartz.task;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.quartz.service.IPlanBusBService;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description
 * @Author caiyanshan
 * @Date 2021/6/18 9:19
 * @Param
 * @Return
 */
@Component("planTaskB")
public class PlanTaskB {
  
  @Autowired
  private IPlanBusBService planBusBService;

  @Autowired
  private ISysConfigService configService;
  
  public void planAm(Integer day) {
    //Date date = null;//测试，上线需屏蔽掉此部分代码
    Date date = DateUtils.getAfterTime(day);
    planBusBService.plan("am", date);
    changeDriveUserTask("am", date);
  }
  
  public void planPm(Integer day) {
    Date date = DateUtils.getAfterTime(day);
    planBusBService.plan("pm", date);
    changeDriveUserTask("pm", date);
  }

  private void changeDriveUserTask(String driveTimes, Date date){
    String value = configService.selectConfigByKey("change_task");
    if("0".equals(value)){
      planBusBService.changePlanUser(driveTimes, date);
    }
  }
  
}
